// 创建右键菜单项
chrome.runtime.onInstalled.addListener(() => {
  chrome.contextMenus.create({
    id: "kittlen_min_show",
    title: "画中画",
    contexts: ["page"],
  });
});

// 监听右键菜单项的点击事件
chrome.contextMenus.onClicked.addListener((info, tab) => {
  if (info.menuItemId === "kittlen_min_show" && tab && tab.id) {
    chrome.tabs.sendMessage(tab.id, { action: info.menuItemId, info, tab }, (response) => {
      if (chrome.runtime.lastError) {
        console.error(JSON.stringify(chrome.runtime.lastError));
      }
    });
  }
});

// background.js
chrome.action.onClicked.addListener((tab) => {
  chrome.scripting.executeScript({
    target: { tabId: tab.id },
    files: ['popup.js']
  });
});